/**
 * Created by python on 19-8-26.
 */

let app = new Vue({
    el: '#app',
    data: {
        user_id: sessionStorage.user_id || localStorage.user_id,
        token: sessionStorage.token || localStorage.token,
        content:'',


    },

    mounted(){
        CKEDITOR.replace('editor2', {"filebrowserUploadUrl": "http://127.0.0.1/ckeditor/upload/"});
    },
    computed: {},
    methods: {
        onsubmit_complain: function () {
            let spit_content = CKEDITOR.instances.editor_text.getData();
            // let spit_id = get_query_string('id');
            if (spit_content) {
                if (this.user_id && this.token) {
                    axios.post(HOST + 'complains/send_complain/',
                        {
                            user_id: this.user_id,
                            content: spit_content,
                            // spit_id: spit_id
                        }
                        ,
                        {
                            headers: {
                                'Authorization': 'JWT ' + this.token
                            },


                        }
                    )
                        .then(response => {
                            alert('发布成功');
                            console.log(response.data);
                            location.href = '/spit-index.html';
                        })
                        .catch(error => {
                            console.log(error.response.data);
                        })
                } else {
                    location.href = 'person-loginsign.html?next=/spit-submit.html';
                }
            } else {
                alert('吐槽内容不允许为空')
                return false
            }

            ;

        },
    }

})